import { msg } from '../notice/notice';
import { hasApp } from '/imports/models/ChannelApps';

Template.app_list_item.helpers({
  hasApp: function () {
    return hasApp(Template.instance().data.result._id, Template.instance().data.channelId);
  }
});

Template.app_list_item.events({
  'click .install-app' (e, instance) {
    e.preventDefault();
    const options = {
      appId: instance.data.result._id,
      channelId: instance.data.channelId
    };

    Meteor.call('installApp', options, (err, res) => {
      if (res) {
        msg({content: '应用安装成功，快去使用吧'});
        // $('#app-store').modal('hide');
      }
    });
  }
});